<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/8
 * Time: 18:06
 */

namespace App;


use Illuminate\Database\Eloquent\Model;

class Tag extends Model
{
    // 表名称
    protected $table = 'tag';
    // 开启自动时间戳
    public $timestamps = true;
    // 日期都存储为时间戳
    protected $dateFormat = 'U';

    public function tag()
    {
        return $this->hasMany('App\Tag', 'parent_id', 'id');
    }

    public function category()
    {
        return $this->belongsToMany('App\Category', 'category_mapping_tag', 'tag_id', 'category_id');
    }

    public function setIsRadioboxAttribute($value)
    {
        $this->attributes['is_radiobox'] = $value ? 1 : 0;
    }
}